import React from "react"

import http from "@/api/helper/request"

import {
	IQueryItemDetailParams,
	IQueryListParams,
	IRefreshOrderStatusParams,
	IResponseItem,
	IResponseItemDetail,
	IUpdateLockParams
} from "./types"

export const LIST_URL = {
	URL1: "/proxyWithDrawUser/onlinePay/selectProxyWithDrawAudit1Page",
	URL2: "/proxyWithDrawUser/onlinePay/selectProxyWithDrawAudit2Page",
	URL3: "/proxyWithDrawUser/onlinePay/selectProxyWithDrawAudit3Page",
	URL4: "/proxyWithDrawUser/onlinePay/selectProxyWithDrawAudit4Page"
}

const useApi = () => {
	const { useState } = React
	const [loading, setLoading] = useState(false)

	async function generalHttp<T>(url: string, body: object | undefined, config: object = {}) {
		setLoading(true)
		let ret = await http.post<T>(url, body, config)
		setLoading(false)
		return ret
	}

	const list = (url: string, body?: IQueryListParams) => generalHttp<Business.TableResourceType<IResponseItem>>(url, body)

	const detail = (body?: IQueryItemDetailParams) =>
		generalHttp<IResponseItemDetail>("/proxyWithDrawUser/onlinePay/proxyWithdrawAuditDetail", body)

	const memberWithDrawProxyUpdateWithdrawLock = (body?: IUpdateLockParams) =>
		generalHttp("/proxyWithDrawUser/updateWithdrawLock", body)

	const memberWithDrawProxyUpdateWithdraw = (body?: IUpdateLockParams) => generalHttp("/proxyWithDrawUser/updateWithdraw", body)

	const proxyWithDrawUserRefreshOrderStatus = (body?: IRefreshOrderStatusParams) =>
		generalHttp("/proxyWithDrawUser/refreshOrderStatus", body)

	return {
		loading,
		generalHttp,
		list,
		detail,
		memberWithDrawProxyUpdateWithdrawLock,
		memberWithDrawProxyUpdateWithdraw,
		proxyWithDrawUserRefreshOrderStatus
	}
}

export default useApi
